package com.link.base.core.basic.util.datax;

import java.util.ArrayList;
import java.util.List;

/**
 * 毕业季H5
 * @author 何启谦
 * @date 2019/5/29
 */
public class BiYeJi {

    /**
     * 毕业季：用户
     *
     * @author 何启谦
     * @date 2019/05/29
     */
    public static String userTemp() {
        //临时表主键名称
        String tempTablePrimaryKeyFieldName = "id";
        // 临时表名称
        String tempTableName = "byj_user";
        // 正式表名称
        String targetTableName = "lnk_accnt";
        // 填充字段信息
        List<FieldMapping> fieldList = new ArrayList<>();
        fieldList.add(new FieldMapping("lc_last_sync_time", "syn_date", "DATETIME"));
        fieldList.add(new FieldMapping("str_to_date(t1.apply_time, '%Y-%m-%d %H:%i:%S')", "qd_sync_date", "DATETIME"));

        fieldList.add(new FieldMapping("nick_name", "wx_nickname", "VARCHAR(255)"));
        fieldList.add(new FieldMapping("openid", "wx_open_id", "VARCHAR(255)"));
        fieldList.add(new FieldMapping("unionid", "wx_unionid", "VARCHAR(300)"));
        fieldList.add(new FieldMapping("head_img", "wx_headimgurl", "VARCHAR(255)"));

        fieldList.add(new FieldMapping("'wx1fc6b1eab4d9a896'", "app_id", "VARCHAR(100)"));
        fieldList.add(new FieldMapping("'wx1fc6b1eab4d9a896'", "ACCT_CHANNEL", "VARCHAR(100)"));
        fieldList.add(new FieldMapping("'ADD_H5'", "subscribe_scene", "VARCHAR(100)"));
        fieldList.add(new FieldMapping("'C'", "acct_level", "VARCHAR(50)"));
        fieldList.add(new FieldMapping("'Fans'", "acct_type", "VARCHAR(100)"));
        fieldList.add(new FieldMapping("'0'", "wx_is_subscribe", "VARCHAR(100)"));

        return DataxUtil.createProcedureCode(tempTablePrimaryKeyFieldName, tempTableName, targetTableName, fieldList, "ACCT_CHANNEL", false);
    }

    /**
     * 毕业季：报名信息
     *
     * @author 何启谦
     * @date 2019/05/29
     */
    public static String signUpTemp() {
        //临时表主键名称
        String tempTablePrimaryKeyFieldName = "id";
        // 临时表名称
        String tempTableName = "byj_signup_result";
        // 正式表名称
        String targetTableName = "lnk_signup_result";
        // 填充字段信息
        List<FieldMapping> fieldList = new ArrayList<>();
        fieldList.add(new FieldMapping("'BiYeJi'", "from_platform", "varchar(100)"));
        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_accnt s1 where "
                + "s1.wx_open_id = t1.openid and s1.ACCT_CHANNEL = 'wx1fc6b1eab4d9a896' limit 1)", "accnt_id", "varchar(50)").setRequired(true));
        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_saleactivity s1 "
                + "where s1.row_id = linkcrm.get_lov_name('000','TOOL_CODE','GSsignup') limit 1)", "sale_act_id", "varchar(50)").setRequired(true));
        fieldList.add(new FieldMapping("school_name", "school", "varchar(50)"));
        fieldList.add(new FieldMapping("name", "name", "VARCHAR(255)"));
        fieldList.add(new FieldMapping("cellphone", "mobile_phone", "varchar(100)"));

        fieldList.add(new FieldMapping("province", "province", "varchar(100)"));
        fieldList.add(new FieldMapping("city", "city", "varchar(100)"));
        fieldList.add(new FieldMapping("distriction", "district", "varchar(100)"));
        fieldList.add(new FieldMapping("detail_addr", "address", "varchar(100)"));
        fieldList.add(new FieldMapping("(case t1.status when 0 then 'Approving' when 1 then 'Approved' when 2 then 'Refused' else t1.status end)",
                "verify_status", "varchar(50)"));

        return DataxUtil.createProcedureCode(tempTablePrimaryKeyFieldName, tempTableName, targetTableName, fieldList, "from_platform");
    }

    /**
     * 毕业季：好友推荐
     *
     * @author 何启谦
     * @date 2019/05/29
     */
    public static String accntCampMonitorTemp() {
        //临时表主键名称
        String tempTablePrimaryKeyFieldName = "id";
        // 临时表名称
        String tempTableName = "byj_accnt_camp_monitor";
        // 正式表名称
        String targetTableName = "lnk_accnt_camp_monitor";
        // 填充字段信息
        List<FieldMapping> fieldList = new ArrayList<>();
        fieldList.add(new FieldMapping("'BiYeJi'", "from_platform", "varchar(100)"));
        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_accnt s1 where "
                + "s1.wx_open_id = t1.openid and s1.ACCT_CHANNEL = 'wx1fc6b1eab4d9a896' limit 1)", "accnt_id", "varchar(50)").setRequired(true));

        fieldList.add(new FieldMapping("(select s2.row_id from sync_temp.byj_user s1 join linkcrm.lnk_accnt s2 "
                + "where s1.id = t1.recommender_id and s2.wx_open_id = s1.openid and s2.ACCT_CHANNEL = 'wx1fc6b1eab4d9a896' limit 1)",
                "source_accnt_id", "varchar(50)").setRequired(true));

        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_saleactivity s1 "
                + "where s1.row_id = linkcrm.get_lov_name('000','TOOL_CODE','GSshare') limit 1)",
                "sal_acct_id", "varchar(50)").setRequired(true));

        fieldList.add(new FieldMapping("(case t1.status when 0 then 'Approving' when 1 then 'Approved' when 2 then 'Refused' else t1.status end)",
                "status", "varchar(50)"));
        fieldList.add(new FieldMapping("'Success'", "action_type", "varchar(100)"));

        return DataxUtil.createProcedureCode(tempTablePrimaryKeyFieldName, tempTableName, targetTableName, fieldList, "from_platform");
    }

    /**
     * 毕业季：中奖信息
     *
     * @author 何启谦
     * @date 2019/05/29
     */
    public static String giftRecordTemp() {
        //临时表主键名称
        String tempTablePrimaryKeyFieldName = "id";
        // 临时表名称
        String tempTableName = "byj_gift_record";
        // 正式表名称
        String targetTableName = "lnk_inner_coupons_accnt";
        // 填充字段信息
        List<FieldMapping> fieldList = new ArrayList<>();
        fieldList.add(new FieldMapping("'BiYeJi'", "from_platform", "varchar(100)"));

        fieldList.add(new FieldMapping("(select s2.row_id from sync_temp.byj_user s1 join linkcrm.lnk_accnt s2 "
                + "where s1.id = t1.user_id and s2.wx_open_id = s1.openid and s2.ACCT_CHANNEL = 'wx1fc6b1eab4d9a896' limit 1)",
                "accnt_id", "varchar(50)").setRequired(true));

        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_coupons s1 join linkcrm.lnk_saleactivity s2 "
                + "on s1.activity_id = s2.row_id where s1.integration_id = t1.gift_id and s2.from_platform = 'BiYeJi' limit 1)",
                "coupons_id", "varchar(50)").setRequired(true));

        fieldList.add(new FieldMapping("time", "claim_time", "datetime"));

        return DataxUtil.createProcedureCode(tempTablePrimaryKeyFieldName, tempTableName, targetTableName, fieldList, "from_platform");
    }

    /**
     * 毕业季：照片表
     *
     * @author 何启谦
     * @date 2019/05/29
     */
    public static String photoTemp() {
        //临时表主键名称
        String tempTablePrimaryKeyFieldName = "id";
        // 临时表名称
        String tempTableName = "byj_photo";
        // 正式表名称
        String targetTableName = "lnk_activity_pic";
        // 填充字段信息
        List<FieldMapping> fieldList = new ArrayList<>();
        fieldList.add(new FieldMapping("'BiYeJi'", "from_platform", "varchar(100)"));

        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_saleactivity s1 "
                + "where s1.row_id = linkcrm.get_lov_name('000','TOOL_CODE','GSphoto') limit 1)",
                "activity_id", "varchar(50)").setRequired(true));

        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_accnt s1 where "
                + "s1.wx_open_id = t1.openid and s1.ACCT_CHANNEL = 'wx1fc6b1eab4d9a896' limit 1)",
                "account_id", "varchar(50)").setRequired(true));

        fieldList.add(new FieldMapping("(case t1.status when 0 then 'Approving' when 1 then 'Approved' when 2 then 'Refused' else t1.status end)",
                "status", "varchar(100)"));

        fieldList.add(new FieldMapping("time", "pic_upload_date", "datetime"));

        return DataxUtil.createProcedureCode(tempTablePrimaryKeyFieldName, tempTableName, targetTableName, fieldList, "from_platform");
    }
}
